var layer;
var form;
var table;
var upload;
var laydate;

layui.use([ 'layer',  'form',  'table' ,  'laydate',  'upload' ],  function() {
	layer = layui.layer;
	form = layui.form;
	table = layui.table;
	upload = layui.upload;
	laydate = layui.laydate; 


	// 执行一个 table 实例=============================================================================================
	table.render({
		elem : '#data_table', 
		id : 'data_table', 
		url : ctxPath+'${cfg.controllerUrl}/${cfg.entityMin}/select',
		title : '${cfg.title}',
		//height:'full-120',
		skin:'line',
		//size:"sm", 
		page : true, 
		toolbar : "#toolberLeft", 
		cols : [[ 
			{type : 'checkbox', fixed : 'left'}, // , width: '150'
		<#list table.fields as field>
			{field : '${field.propertyName}', title : '${field.comment}', minWidth: '150', sort : true, align : 'center', hide: setColumnHide("${field.propertyName}")},
		</#list>
			{fixed : isRight(), align : 'center', minWidth: '180', title : '操作', toolbar : '#toolRow'}
		]]
		,done:function(result,currPage,count){
	    }
	});
	
	// 头部左侧事件=============================================================================================
	table.on('toolbar(data_table)',  function(obj) {
		if (obj.event === 'search') {
			openWindowSearch('search_form', "条件搜索", '100%', 'auto', false, 0, false, false, null, 0.2, true)
		}else if(obj.event === 'add'){
			openWindowRB('data_form', "添加", '600px', '100%', false, 0, false, false, null, 0.2, false);
		}else if(obj.event === 'delete'){
            deleteBatch(table, 'data_table', "id", ctxPath+'${cfg.controllerUrl}/${cfg.entityMin}/deleteBatch')
		}
	})
	
	// 行监听事件=============================================================================================
	table.on('tool(data_table)',  function(obj) {
		var data = obj.data;
		if (obj.event === 'del') {
			deleteRow(table, 'data_table', data, ctxPath+'${cfg.controllerUrl}/${cfg.entityMin}/delete'+"?id="+data.id);
		} else if (obj.event === 'edit') {
			openWindowRB('data_form', "编辑", '700px', '100%', false, 0, false, false, data, 0.2, false);
		} else if (obj.event === 'detail') {
			openWindowRB('data_form', "查看", '700px', '100%', false, 0, false, false, data, 0.2, false);
		}
	});
	
	// 查询=============================================================================================
	form.on('submit(submitSearch)',  function(data) {
		reloadTable(table, 'data_table', data.field);
		return false;
	})
	
	// 提交=============================================================================================
	form.on('submit(submitForm)',  function(data) {
		data.field = filterField('#data_form', data.field);
		saveData(table, 'data_table', data.field, data.field.id ? ctxPath+'${cfg.controllerUrl}/${cfg.entityMin}/edit' : ctxPath+'${cfg.controllerUrl}/${cfg.entityMin}/add', '#data_form');
		return false;
	})



})


/**
 * -----------------------------------------------------------------------------------------------------------------------------------------
 * 逻辑处理
 */
function operation() {

}





